﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Shine.Framework;
using SuperMap.Data;
using SuperMap.Realspace;

namespace Shine.Tool
{
    public partial class FrmScreenSetting : Office2007Form
    {
        IApplication m_Application = null;
        Scene m_Scene = null;
        IList<Layer3DVectorFile> lyrFactory = new List<Layer3DVectorFile>();
        static FrmScreenSetting m_instance = null;

        public FrmScreenSetting(IApplication application)
        {
            this.m_Application = application;
            InitializeComponent();
        }

        private void InitializeComboBox(Scene _scene)
        {
            if (m_Application != null)
            {
                //for (int dsIdx = 0; dsIdx < this.m_workspace.Datasources.Count; dsIdx++)
                //{
                //    //string dsName = this.m_workspace.Datasources[dsIdx].Alias;
                //    for(int lyrIdx = 0;lyrIdx<this.m_workspace.Datasources[dsIdx].Datasets.Count)
                //    {
                //        DatasetVector datasetModel = this.m_workspace.Datasources[dsIdx].Datasets[lyrIdx] as DatasetVector;

                //    }
                //}

                Layer3Ds lyr3Ds = _scene.Layers;
                for (int idx = 0; idx < lyr3Ds.Count; idx++)
                {
                    Layer3D lyr = lyr3Ds[idx];
                   
                    if (lyr is Layer3DVectorFile)
                    {
                        lyrFactory.Add((Layer3DVectorFile)lyr);
                        ComboBoxItem obj = new ComboBoxItem();
                        obj.Text = lyr.Name;
                        obj.Tag = lyr;
                        this.cbxLeftScreen.Items.Add(obj);
                        this.cbxRightScreen.Items.Add(obj);
                    }
                }

                //this.cbxLeftScreen.SelectedIndex = 0;
                //this.cbxRightScreen.SelectedIndex = 0;
            }
        }

        public static FrmScreenSetting Instance(IApplication application)
        {
            if (m_instance == null || m_instance.IsDisposed)
            {
                m_instance = new FrmScreenSetting(application);
            }

            return m_instance;
        }

        private void cbxLeftScreen_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = this.cbxLeftScreen.SelectedIndex;
            (m_Application as IFramework).LeftScreenLayer = ((ComboBox)(this.cbxLeftScreen.Items[idx])).Tag as Layer3DVectorFile;
        }

        private void cbxRightScreen_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = this.cbxRightScreen.SelectedIndex;
            (m_Application as IFramework).RightScreenLayer = ((ComboBox)(this.cbxRightScreen.Items[idx])).Tag as Layer3DVectorFile;
        }

        private void FrmScreenSetting_Load(object sender, EventArgs e)
        {
            this.m_Scene = (m_Application as IFramework).SceneControl.Scene;
            this.InitializeComboBox(m_Scene);
        }
    }
}
